<?php
/**
 * Yotaku shop - yshop
 * Copyright (c) 2016 http://www.yotaku.cn All rights reserved.
 * Author: Creatint <creatint@163.com> <http://creatint.yotaku.cn>
 */
namespace Home\Controller;
class GoodsController extends HomeController{
    //列表
    public function index(){
        //获取条件
        $params = I('get.',0);


        //获取分类数据
        $Category   =   D("Category");
        $categorys   =   $Category->getCategory();
        $this->assign('categorys',$categorys);

        //获取当前分类数据
        $category = $Category->getDetail($params['category']);
        $this->assign("category",$category);

        //获取分类子级
        if(is_numeric($params['category'])){
            $params['category'] = array('in',get_children($params['category'],$categorys,'id'));
        }

        //取出条件内商品
        $Goods   =   D("Goods");
        $goodss   =   $Goods->getGoods($params,$page=false);

        $this->assign('category_id',$params['category_id']);
        $this->assign('goodss',$goodss);
        $this->display();
    }

    //商品详情1
    function detail(){
        $id = I("get.id",0);
        $Goods = D("Goods");
        $info = $Goods->getDetail($id);
        $info['images']  =   get_item_imgs($info['multimage'],0,'path');
        $info['content'] = html_entity_decode($info['content']);

        if(I('get.activity','no') == 'yes' && ($activity_info = hook('activity_info',$info))){
            $info['activity_info'] = array_merge($activity_info);
        }
 
        trace($info,'info');
        $this->assign('info',$info);

        if(I("activity",'no') == 'yes'){
            $activity = hook('get_activity');
            $this->assign('activity',$activity);
            $this->display("detail-second");
        }else{
            $this->display("detail");
        }
    }

    //商品详情2
    function detail2(){
        $id = I('id',0);
        $Goods = D("Goods");
        $info = $Goods->getDetail($id);
        $info['images']  =   get_item_imgs($info['multimage'],0,'path');
        $info['content'] = html_entity_decode($info['content']);

        if(I('get.activity','no') == 'yes' && ($activity_info = hook('activity_info',$info))){
            $info['activity_info'] = array_merge($activity_info);
        }

        trace($info,'info');
        $this->assign('info',$info);

        if(I("activity",'no') == 'yes'){
            $activity = hook('get_activity');
            $this->assign('activity',$activity);
        }

        $this->display();
    }

    public function second(){
        $activity = hook('get_activity');

//        dump($activity);
        $this->assign('activity',$activity);

        $this->display();
    }
}